package com.zy.controller;

import com.zy.util.EncryptUtil;
import com.zy.util.ResponseUtil;
import com.zy.vo.ResponseVO;
import lombok.Data;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhy
 * @date 2025/6/21 15:25
 */
@RestController
@RequestMapping("/api")
public class ApiController {
    /**
     * AES加密解密
     *
     * @param encryptInput 当 content 包含有 ENCRY() 时，该方法为解密操作；否则为加密操作
     * @return
     */
    @PostMapping(value = "/encrypt")
    public ResponseVO<String> encrypt(@RequestBody EncryptInput encryptInput) {
        if (encryptInput == null) {
            return ResponseUtil.success();
        }
        String content = EncryptUtil.doEncrypt(encryptInput.content);
        return ResponseUtil.success(content);
    }

    @Data
    public static class EncryptInput {
        private String content;
    }
}
